package com.sun.umbrella.session.websession;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.mgt.eis.CachingSessionDAO;
import org.springframework.beans.factory.annotation.Autowired;

import java.io.Serializable;

/**
 * @author Jay
 * @version v1.0
 * @description web session
 * @date 2017-12-08 18:47
 */
public class UmbrellaSessionDAO extends CachingSessionDAO {

    @Autowired
    private UmbrellaSessionProxy umbrellaSessionProxy;

    /**
     * 更新session
     *
     * @param session
     */
    @Override
    protected void doUpdate(Session session) {
        umbrellaSessionProxy.updateSession(session);
    }

    /**
     * 删除session
     *
     * @param session
     */
    @Override
    protected void doDelete(Session session) {
        umbrellaSessionProxy.deleteSession(session);
    }

    /**
     * 创建session
     *
     * @param session
     * @return
     */
    @Override
    protected Serializable doCreate(Session session) {
        Serializable sessionId = umbrellaSessionProxy.createSession(session);
        assignSessionId(session, sessionId);
        return sessionId;
    }

    /**
     * 取session
     *
     * @param sessionId
     * @return
     */
    @Override
    protected Session doReadSession(Serializable sessionId) {
        return umbrellaSessionProxy.getSession(sessionId);
    }
}
